/**
 * @file iodev.h
 * @brief IO Devices Interfaces
 *
 * This module supplies the interfaces to the
 * device that be implemented as a IO device
 *
 * @author yemt@witsi.cn
 * @date 2011-08-04
 * @version rxSys.ser.01
 */
#ifndef IODEV_H_
#define IODEV_H_

#include "init.h"
#include <stdint.h>
#include <sys/types.h>
#include "dev.h"
#include "config.h"


#define POLL_READ       0x01    /**< Poll Read Status */
#define POLL_WRITE      0x02    /**< Poll Write Status */
#define POLL_ERROR      0x04    /**< Poll Error Status */

typedef struct _iodev_t iodev_t;        /**< IO Device Type */

/**
 * The structure below represents a IO device
 */
struct _iodev_t {
        const char * name;      /**< IO Device Name */
        const void * priv;      /**< A Pointer to the Device Private Data */
        int (*init)(iodev_t *);                                       /**< Device Initializer */
        ssize_t (*read)(iodev_t *, void* buffer, size_t size);        /**< Device Reader */
        ssize_t (*write)(iodev_t *, const void* buffer, size_t size); /**< Device Writer */
        int (*poll)(iodev_t *, uint32_t);                             /**< Device Poller */
        int (*ioctl)(iodev_t *, uint32_t cmd, void *arg);             /**< Device Controller */
        int (*suspend)(iodev_t *,int sleep);                          /**< Device Enter Sleep Mode */
        int (*wakeup)(iodev_t *, int sleep);                          /**< Device Exit Sleep Mode */
};

iodev_t * iodev_find(const char * name, int *index); /**< Find a IO Device by a Name */
iodev_t * iodev_get(uint32_t nr);                    /**< Get a IO Device by its index */
uint32_t iodev_get_number(void);                     /**< Return the numbers of the Registered IO Devices */
int iodev_suspend(int sleep);
int iodev_wakeup(int sleep);


#include "devinf.h"

#endif /* IODEV_H_ */
